package com.authorization.demo.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @Remarks:
 * @ClassName: UpdateMetaObjectHandler
 * @Author: Micora
 * @CreateTime: 2022/7/15
 */
@Slf4j
@Component
public class UpdateMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createDate",new Date(), metaObject);
        this.setFieldValByName("alterDate", new Date(), metaObject);
        this.setFieldValByName("effectiveDate", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("alterDate", new Date(), metaObject);
    }
}
